/*
 * @lc app=leetcode.cn id=141 lang=javascript
 *
 * [141] 环形链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} head
 * @return {boolean}
 */
var hasCycle = function(head) {
    if (!head || !head.next) {
        return false
    }
    let fast = head.next
    let slow = head
    let flag = false
    while(true) {
        if( slow === fast ) {
            flag = true
            break
        }
        if (!fast || !fast.next) {
            break
        }
        fast = fast.next.next
        slow = slow.next
    }
    return flag
};
// @lc code=end

